//Monday, November 02 2009
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <bitset>
#include <queue>
#include <numeric>

#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;

#define REP(i,n) for(__typeof(n) i=0; i<(n); ++i)
#define FOR(i,a,b) for(__typeof(b) i=a; i<(b); ++i)
#define FOREACH(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)

typedef long long ll;

class BitwiseEquations
{
public:
	long long kthPlusOrSolution(int x, int k)
	{
		bitset<64> b(x);
		bitset<64> c(k);

		long long u = 0;
		for(int i=0; i<32; i++)
		{
			while(b[u]) u++;
			b[u] = c[i];
			u++;
		}
		long long ret = 0;
		for(int i=0; i<64; i++)
		{
			if(b[i])
				ret += (1LL << i);
		}
		return ret - x;
	}
};
